<?php
/*
    GUMUD is Extensible Web-based Multi-User Dungeon Software.

    Copyright (C) 2013  White Rabbit

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
function parserCommandDecode ($itx,$commandstring) {
	$commandstring = trim($commandstring);
	$fooarray= explode(" ",$commandstring);
	$foonummax = getSNumArr($fooarray);
	$x = 1;
	$commandstring2 = "";
	$output = "";
	/*while($x <= $foonummax) {
		$y=$x-1;
		$result = myquery("SELECT * FROM `".dbprfx."alt-lex` WHERE `supp` = '".$fooarray[$y]."' LIMIT 1");
		if($result != "not") {
			$resultarray = myarray($result);
			$commandstring2= $commandstring2." ".$resultarray['realcommand'];
		}
		else {
			$commandstring2= $commandstring2." ".$fooarray[$y];
		}
		$x++;
	}*/
	$commandstring2 = trim($commandstring);
	if (preg_match("/(remove|unwear|take off)+(\p{Zs}|\040|)+(\w)+/",$commandstring2)) {
		$itx['com-inner'][3] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getuser&firstname=".$itx['user']['avatarFirst']."&lastname=".$itx['user']['avatarLast']);
		$var1 = preg_replace("/(remove|unwear|take off)+(\p{Zs}|\040)+/","",$commandstring2);
		$output = "<p><span class='commandname'>Command:</span> <span class='commandentry'>".file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=unwearObject&uuid=".$itx['com-inner'][3]."&object=".urlencode($var1))."</span>";
	writeInventoryResponseFile($itx['com-inner'][3], $output);
	}
	elseif (preg_match("/(wear|equip|put on)+(\p{Zs}|\040|)+(\p{Zs}|\040|\w)+(\p{Zs}|\040|)+(on|in)+(\p{Zs}|\040|)+(hair|head|neck|breasts|pectorals|feet|shoulders|left breast|left pectoral|right breast|right pectoral|right nipple|abdomen|left forearm|rightforearm|left lower arm|right lower arm|left wrist|right wrist|left hand|right hand|left fingers|right fingers|left leg|right leg|left shin|right shin|lower body|left ankle|right ankle|left foot|right foot|feet|left toes|right toes|upper body|whole body)+(\p{Zs}|\040|)+(using layer)+(\p{Zs}|\040|)+(\d)+/",$commandstring2)) {
		$itx['com-inner'][3] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getuser&firstname=".$itx['user']['avatarFirst']."&lastname=".$itx['user']['avatarLast']);
		$var1a = preg_replace("/(wear|equip|put on)+(\p{Zs}|\040|)+/","",$commandstring2);
		$array1a = explode(" using layer ",$var1a);
		$array1b = explode(" on ",$array1a[0]);
		$var1 = $array1b[0];
		$location = $array1b[1];
		$layer = $array1a[1];
		$locationnum = getBodyLocationNum($location);
		$output = "<p><span class='commandname'>Command:</span> <span class='commandentry'>".file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=wearObject&uuid=".$itx['com-inner'][3]."&object=".urlencode($var1)."&order=".$locationnum."&layer=".$layer)."</span>";
	writeInventoryResponseFile($itx['com-inner'][3], $output);
	}
	elseif (preg_match("/(drop|place|put)+(\p{Zs}|\040|)+(\w)+/",$commandstring2)) {
		$itx['com-inner'][3] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getuser&firstname=".$itx['user']['avatarFirst']."&lastname=".$itx['user']['avatarLast']);
		$itx['com-inner'][4] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getUserRegionLoc&uuid=".$itx['com-inner'][3]);
		$itx['com-inner'][5] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getRegionData&uuid=".$itx['com-inner'][4]);
		$array1 = splitData($itx['com-inner'][5]);
		$array2 = splitData(file_get_contents("http://".$array1[3]."/index.php?scripthandshakeID=".scripthandshakeID."&request=getLocalLoc&uuid=".$itx['com-inner'][3]));
		$var1 = preg_replace("/(drop|place|put)+(\p{Zs}|\040)+/","",$commandstring2);
		$output = "<p><span class='commandname'>Command:</span> <span class='commandentry'>".file_get_contents("http://".$array1[3]."/index.php?scripthandshakeID=".scripthandshakeID."&request=putObject&uuid=".$itx['com-inner'][4]."&localX=".$array2[0]."&localY=".$array2[1]."&editor=".$itx['com-inner'][3]."&object=".urlencode($var1))."</span>";
	writeInventoryResponseFile($itx['com-inner'][3], $output);
	}
	elseif (preg_match("/(remove inventory|delete inventory|kill inventory)+(\p{Zs}|\040)+(\w)+/",$commandstring2)) {
		$itx['com-inner'][3] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getuser&firstname=".$itx['user']['avatarFirst']."&lastname=".$itx['user']['avatarLast']);
		
		
		$var1 = preg_replace("/(remove inventory|delete inventory|kill inventory)+(\p{Zs}|\040)+/","",$commandstring2);
		$output = "<p><span class='commandname'>Inventory Delete:</span> <span class='commandentry'>".$var1." ".file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=deleteInventory&uuid=".$itx['com-inner'][3]."&object=".urlencode($var1))."</span>";
	writeInventoryResponseFile($itx['com-inner'][3], $output);
	}
	elseif (preg_match("/(set object|change object|edit object|set item|change item|edit item)+(\p{Zs}|\040)+(type:)+(\w|\p{Zs}|\040)+(::)+(\w)+/",$commandstring2)) {
		$itx['com-inner'][3] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getuser&firstname=".$itx['user']['avatarFirst']."&lastname=".$itx['user']['avatarLast']);
		
		
		$array3 = explode("::",$commandstring2);
		$array4 = explode(":",$array3[0]);
		
		$output = "<p><span class='commandname'>Inventory:</span> <span class='commandentry'>".file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=editInventoryObjectType&uuid=".$itx['com-inner'][3]."&data=".urlencode($array4[1])."&type=".urlencode($array3[1]))."</span>";
	writeInventoryResponseFile($itx['com-inner'][3], $output);
	}
	elseif (preg_match("/(set object|change object|edit object|set item|change item|edit item)+(\p{Zs}|\040)+(description|view)+(\p{Zs}|\040)+(\w|\p{Zs}|\040)+(\p{Zs}|\040)+(using view)+(\p{Zs}|\040)+(\w)+(\p{Zs}|\040)+(using type)+(\p{Zs}|\040)+(\w)+(\p{Zs}|\040)+(with value)+(\p{Zs}|\040)+(\w|\W)+/",$commandstring2)) {
		$itx['com-inner'][3] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getuser&firstname=".$itx['user']['avatarFirst']."&lastname=".$itx['user']['avatarLast']);
		
		
		$array3 = explode(" with value ",$commandstring2);
		$array4 = explode(" using type ",$array3[0]);
		$array5 = explode(" using view ",$array4[0]);
		$str2 = preg_replace("/(set object|change object|edit object|set item|change item|edit item)+(\p{Zs}|\040)+(description|view)+(\p{Zs}|\040)+/","",$array5[0]);
		$str1 = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getInventoryInstanceUUID&uuid=".$itx['com-inner'][3]."&data=".urlencode($str2));
		$output = "<p><span class='commandname'>Command:</span> <span class='commandentry'>".file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=updateInventoryObjectLex&personuuid=".$itx['com-inner'][3]."&uuid=".$str1."&object=".urlencode($str2)."&data=".urlencode($array3[1])."&state=".urlencode($array5[1])."&type=".$array4[1])."</span>";
	writeInventoryResponseFile($itx['com-inner'][3], $output);
	}
	// DEPRECATED
	/*
	elseif (preg_match("/(set object|change object|edit object|set item|change item|edit item)+(\p{Zs}|\040)+(detail)+(\p{Zs}|\040)+(description:|view:)+(\w|\p{Zs}|\040)+(::)+(\w)+(::)+(\w|\W)+/",$commandstring2)) {
		$itx['com-inner'][3] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getuser&firstname=".$itx['user']['avatarFirst']."&lastname=".$itx['user']['avatarLast']);
		
		
		$array3 = explode("::",$commandstring2);
		$array4 = explode(":",$array3[0]);
		$str1 = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getInventoryInstanceUUID&uuid=".$itx['com-inner'][3]."&data=".urlencode($array4[1]));
		$output = "<p><span class='commandname'>Command:</span> <span class='commandentry'>".file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=updateInventoryObjectDetailLex&personuuid=".$itx['com-inner'][3]."&uuid=".$str1."&object=".urlencode($array4[1])."&data=".urlencode($array3[2])."&state=".urlencode($array3[1]))."</span>";
	writeInventoryResponseFile($itx['com-inner'][3], $output);
	}
	*/
	elseif (preg_match("/(create object|create item|create new object|create new item)+(\p{Zs}|\040)+(\w)+/",$commandstring2)) {
		$itx['com-inner'][3] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getuser&firstname=".$itx['user']['avatarFirst']."&lastname=".$itx['user']['avatarLast']);
		$itx['com-inner'][4] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getUserRegionLoc&uuid=".$itx['com-inner'][3]);
		$itx['com-inner'][5] = file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=getRegionData&uuid=".$itx['com-inner'][4]);
		$array1 = splitData($itx['com-inner'][5]);
		$array2 = splitData(file_get_contents("http://".$array1[3]."/index.php?scripthandshakeID=".scripthandshakeID."&request=getLocalLoc&uuid=".$itx['com-inner'][3]));
		$var1 = urlencode(preg_replace("/(create object|create item|create new object|create new item)+(\p{Zs}|\040)+/","",$commandstring2));

		$output = "<p><span class='commandname'>Command:</span> <span class='commandentry'>".file_get_contents("http://".gridURL."/index.php?scripthandshakeID=".scripthandshakeID."&request=createInventoryObject&editor=".$itx['com-inner'][3]."&object=".urlencode($var1))."</span>";
	writeInventoryResponseFile($itx['com-inner'][3], $output);
	}
return $output;
}
?>
